<template>
    <div class="app-container">
      <el-page-header @back="goBack" >
        </el-page-header>
     <el-row :gutter="10" class="mb8" >
      <el-col :span="1.5">
            <el-button type="primary" plain icon="Download" @click="handleExport">导出</el-button>
        </el-col>
    </el-row>
      <div>
        <el-table v-loading="loading" border :data="dataList" height="65vh"
        :summary-method="getSummaries"
        show-summary>
          <el-table-column label="序号" width="60" type="index" align="center" />
          <el-table-column
            label="状态"
            min-width="80"
            align="center"
            :show-overflow-tooltip="true"
            prop="status"
            v-if="columns[0].visible"
          >
            <template v-slot="{ row }">
              <dict-tag
                :options="report_status"
                :value="row.status"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="报工单编码"
            min-width="200"
            align="center"
            :show-overflow-tooltip="true"
            prop="code"
            v-if="columns[1].visible"
          >
            <!-- <template v-slot="{ row }">
              <el-button type="primary" @click="handleView(row)" text>{{
                row.code
              }}</el-button>
            </template> -->
          </el-table-column>
          <el-table-column
            label="生产单编码"
            min-width="180"
            align="center"
            :show-overflow-tooltip="true"
            prop="produceCode"
            v-if="columns[1].visible"
          >
          </el-table-column>
          <el-table-column
            label="实际用纸令数"
            min-width="100"
            align="center"
            prop="realityLing"
            :show-overflow-tooltip="true"
          ></el-table-column>
           <!-- <el-table-column
            label="出版号"
            min-width="140"
            align="center"
            :show-overflow-tooltip="true"
            prop="pubNo"
            v-if="columns[1].visible"
          ></el-table-column> -->
          <el-table-column
            label="机台"
            align="center"
            min-width="220"
            :show-overflow-tooltip="true"
            prop="machineName"
            v-if="columns[4].visible"
          >
          </el-table-column>
          <el-table-column
            label="报工日期"
            width="120"
            align="center"
            :show-overflow-tooltip="true"
            prop="reportDate"
            v-if="columns[2].visible"
          >
            <template v-slot="{ row }">
              {{ row.reportDate ? row.reportDate.split(" ")[0] : "" }}
            </template>
          </el-table-column>
          <el-table-column
            label="上报人"
            min-width="100"
            align="center"
            :show-overflow-tooltip="true"
            prop="createBy"
            v-if="columns[3].visible"
          >
          </el-table-column>
          <el-table-column
            label="品种"
            min-width="100"
            prop="breed"
            align="center"
          ></el-table-column>
          <el-table-column
            label="书刊名称"
            min-width="240"
            prop="orderName"
            align="center"
          ></el-table-column>
          <el-table-column
            label="印张"
            min-width="60"
            align="center"
            :show-overflow-tooltip="true"
            prop="sheet"
          ></el-table-column>
          <el-table-column
            label="贴数"
            min-width="60"
            align="center"
            :show-overflow-tooltip="true"
            prop="labeling"
          ></el-table-column>
          <el-table-column
            label="印数"
            min-width="60"
            align="center"
            prop="printAmount"
          ></el-table-column>
          <el-table-column
            label="完成数量"
            min-width="120"
            align="center"
            prop="finishNum"
          ></el-table-column>
          <el-table-column
            label="计件令数"
            align="center"
            prop="pieceLing"
          ></el-table-column>
          <el-table-column
            label="计件标准"
            min-width="120"
            align="center"
            :show-overflow-tooltip="true"
            prop="standard"
          ></el-table-column>
          <el-table-column
            label="计件金额"
            align="center"
            :show-overflow-tooltip="true"
            prop="amount"
          ></el-table-column>
          <el-table-column
            label="印色"
            align="center"
            :show-overflow-tooltip="true"
            prop="printColor"
          >
            <template #default="scope">
              <dict-tag
                :options="ems_order_print_color"
                :value="scope.row.printColor"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="换版数量"
            min-width="120"
            align="center"
            :show-overflow-tooltip="true"
            prop="exchangeNum"
          ></el-table-column>
          <el-table-column
            label="计件标准(换版)"
            min-width="120"
            align="center"
            prop="standardH"
          ></el-table-column>
          <el-table-column
            label="计件金额(换版)"
            align="center"
            :show-overflow-tooltip="true"
            prop="amountH"
          ></el-table-column>
          <el-table-column
            label="预计用纸令数"
            min-width="120"
            align="center"
            prop="expectLing"
          >
          </el-table-column>
          <el-table-column
            label="盈亏令数"
            min-width="100"
            align="center"
            prop="ykLing"
          ></el-table-column>
          <el-table-column
            label="另行加放"
            min-width="100"
            align="center"
            prop="lxjf"
          ></el-table-column>
          <el-table-column
            label="累计已上报数量"
            align="center"
            prop="totalNum"
          ></el-table-column>
          <el-table-column
            label="最大允许上报数量"
            align="center"
            prop="maxNum"
          ></el-table-column>
          <el-table-column
          label="吨位系数"
          align="center"
          prop="tonnageCoefficient"
        ></el-table-column>
          <el-table-column
            label="损耗比例"
            align="center"
            prop="lossCoefficient"
          ></el-table-column>
          <!-- <el-table-column
              label="当班日期"
              min-width="120"
              align="center"
              :show-overflow-tooltip="true"
              prop="dutyDate"
              v-if="columns[6].visible"
            >
              <template v-slot="{ row }">
                {{ row.dutyDate ? row.dutyDate.split("T")[0] : "" }}
              </template>
            </el-table-column> -->
          <el-table-column
            label="备注"
            min-width="120"
            align="center"
            :show-overflow-tooltip="true"
            prop="remark"
            v-if="columns[7].visible"
          >
          </el-table-column>
          <el-table-column
            label="创建人"
            min-width="120"
            align="center"
            :show-overflow-tooltip="true"
            prop="createBy"
            v-if="columns[8].visible"
          >
          </el-table-column>
          <el-table-column
            label="创建时间"
            min-width="120"
            align="center"
            :show-overflow-tooltip="true"
            prop="createTime"
            v-if="columns[9].visible"
          >
            <template v-slot="{ row }">
              {{ row.createTime ? row.createTime.split("T")[0] : "" }}
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </template>
    
    <script setup>
  import { downLoadBlob } from "@/utils/ruoyi";
  import { getReportDetailByRealityLing ,exportReportRealityLing} from "@/api/production/printReport.js";
  import useTagsViewStore from "@/store/modules/tagsView";
  import { toNumber } from "@/utils/ruoyi";

  const { proxy } = getCurrentInstance();
  const loading = ref(true);
  const dataList = ref([]);
  const total = ref(0);
  const router = useRouter();
  const route = useRoute();
  const tagsViewStore = useTagsViewStore();
  const realityLingSum = ref(0);

  const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 30,
    status: "2",
  },
});
const { queryParams } = toRefs(data);

    // 列显隐信息
    const columns = ref([
    { key: 0, label: `状态`, visible: true },
    { key: 1, label: `报工单编码`, visible: true },
    { key: 2, label: `实际用纸令数`, visible: true },
    { key: 3, label: `机台`, visible: true },
    { key: 4, label: `报工日期`, visible: true },
    { key: 5, label: `上报人`, visible: true },
    { key: 6, label: `品种`, visible: true },
    { key: 7, label: `书刊名称`, visible: true },
    { key: 8, label: `创建人`, visible: true },
    { key: 9, label: `创建时间`, visible: true },
  ]);
  
  // 合计
const getSummaries = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = "合计";
      return;
    }
    switch (column.property) {
      case "realityLing":
        sums[index] = realityLingSum.value;
        break;
      default:
        break;
    }
  });
  return sums;
};
  
  const { ems_production_audit, report_status, ems_order_print_color } =
    proxy.useDict(
      "ems_production_audit",
      "report_status",
      "ems_order_print_color"
    );
  
  const getList = () => {
    loading.value = true;
    if(route.query?.paperId){
      queryParams.value.paperId=route.query.paperId;
      queryParams.value.startDate=route.query.startDate;
      queryParams.value.endDate=route.query.endDate;
      if(route.query.machineId!='5ce9c01407214812904ebbce9c405830'){
        queryParams.value.machineId=route.query.machineId;
      }else{
        queryParams.value.machineId='5ce9c01407214812904ebbce9c405830,325eb4a641ef4d5fb1d42d275d607e21';
      }
    }
    
    getReportDetailByRealityLing(queryParams.value)
      .then((res) => {
        loading.value = false;
        if (res.rows.length > 0) {
            realityLingSum.value=res.rows[0].realityLingSum;
        }
        dataList.value = res.rows;
        total.value = res.total;
      })
      .catch((err) => {
        loading.value = false;
      });
  };
  
  // 查看
  const handleViewProduce = (row, index) => {
    const produceId = row.produceId;
    if (row.produceCode.includes('FM')) {
      router.push({
        path: "/production/cover/coverDetails",
        query: {
          id: produceId,
          info: true,
          moduleCode: "searchReportDetail",
        },
      });
    } else {
      router.push({
        path: "/production/text/textDetails",
        query: {
          id: produceId,
          info: true,
          moduleCode: "searchReportDetail",
        },
      });
    }
  };
  
  // 查看
  const handleView = (row) => {
    router.push({
      path: "/production/printReport/printReportDetails",
      query: {
        id: row.reportId,
        info: true,
      },
    });
  };
  

  // 导出
const handleExport = () => {
  exportReportRealityLing(queryParams.value).then((res) => {
    downLoadBlob(res, "报工明细");
  });
};

  //  返回
  const goBack = () => {
    setTimeout(() => {
    router.go(-1);
    tagsViewStore.delView(route);
  }, 0);
  };
  

  getList();
  </script>
    
    <style lang="scss" scoped></style>
    